package game.particle;


import org.lwjgl.opengl.GL11;

import engine.j2d.Color;
import engine.math.Vector2f;

public class Particle
{
	public Vector2f pos = new Vector2f(0, 0);
	public Vector2f size = new Vector2f(0, 0);
	public Vector2f vel = new Vector2f(0, 0);
	private Vector2f posSave= new Vector2f(0,0);
	private Color color = new Color(0, 0, 0);
	private double life;
	private double sevedLife;
	private float decSpeed = 0;
	
	Particle(Vector2f pos, Vector2f size, Vector2f velocity,
			Color col, float l)
	{
		this.pos = pos;
		this.size = size;
		vel = velocity;
		color = col;
		sevedLife = life = l;
		posSave.x = pos.x;
		posSave.y = pos.y;
	}

	Vector2f getPos() {
		return pos;
	}

	void setPos(Vector2f newPos) {
		pos = new Vector2f(newPos);
	}

	Vector2f getSize() {
		return size;
	}

	void setSize(Vector2f newSize) {
		size = new Vector2f(newSize);
	}

	Vector2f getVelocity() {
		return vel;
	}

	void setVelocity(Vector2f v) {
		vel.x = v.x;
		vel.y = v.y;
	}

	double getLife() {
		return life;
	}

	void setDLife(float l) {
		life -= l;
	}

	float getSpeed() {
		return decSpeed;
	}

	void setSpeed(float s) {
		decSpeed = s;
	}

	void render() {
		GL11.glPushMatrix();
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
		GL11.glDisable(GL11.GL_DEPTH_TEST);
		GL11.glEnable(GL11.GL_BLEND);
		GL11.glTranslatef(pos.x, pos.y, 0);

		GL11.glColor4f(color.r, color.g, color.b, (float) life);
		GL11.glBegin(GL11.GL_QUADS);
		GL11.glTexCoord2f(0, 0);
		GL11.glVertex2f(0, 0);
		GL11.glTexCoord2f(0, 1);
		GL11.glVertex2f(0, size.y);
		GL11.glTexCoord2f(1, 1);
		GL11.glVertex2f(size.x, size.y);
		GL11.glTexCoord2f(1, 0);
		GL11.glVertex2f(size.x, 0);
		GL11.glEnd();
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
		GL11.glPopMatrix();
	}

	void move() {
		pos.x += vel.x;
		pos.y += vel.y;
		if (life < 0.05f) {
			pos.x = posSave.x;
			pos.y = posSave.y;
			life = sevedLife;
		}
	}

	void gravity() {
		move();
		pos.y *= 0.991f;
	}
}
